package picture

/*
#include "LayoutAnalysis.h"

// intentionally write the same LDFLAGS differently
#cgo CFLAGS : -I.
#cgo linux LDFLAGS: -L. -lLayout -lstdc++
#cgo darwin LDFLAGS: -L. -lLayout -lstdc++
*/
import "C"

import (
	"fmt"
	"image"
	// "unsafe"
)

/*
调用so
TODO 内存释放是否需要优化
*/
func getImgLineBySO(pic *image.Gray) (result [][]int) {
	maxlength := 5000
	size := pic.Bounds()
	Cwidth := C.int(size.Max.X)
	Cheight := C.int(size.Max.Y)
	Cresult := make([]C.int, maxlength)
	CpbImage := make([]C.uchar, size.Max.X*size.Max.Y)
	for k, v := range pic.Pix {
		CpbImage[k] = C.uchar(v)
	}
	count := C.hw_SegmentHomework(&Cresult[0], C.int(maxlength), &CpbImage[0], Cwidth, Cheight)
	fmt.Println("result", count, Cresult)

	for i := 0; i < int(count); i++ {
		var tmpArr []int
		for j := 0; j < 4; j++ {
			tmpArr_tmp := int(Cresult[i*4+j])
			tmpArr = append(tmpArr, tmpArr_tmp)
		}
		result = append(result, tmpArr)
	}
	return
}
